﻿<script language="javascript" type="text/javascript">
    function SubmitSearchForm() {
        $('#frmSearch').submit();
    }
    $(function () {
        $("#txtKeyword").autocomplete({
            source: function (request, response) {                
                $.ajax({
                url: "/product/GetAutoCompleteSearchResult?keyword=" + $('#txtKeyword').val() + "&maxlength=20",                
                success: function( result ) {
                    var products = eval('(' + result + ')');
                    response($.map(products, function (product) {
                        return {
                                label: product.Title,
                                value: product.Title //product.ID
                            }
                        }));
                    }
                });
            },
            minLength: 2,
            select: function (event, ui) {
                $(this).val(ui.item.label);
                SubmitSearchForm();
            },
            open: function () {
                $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
            },
            close: function () {
                $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
            }
        });
    });
</script>